package com.ibiaoke.boss.controller;
import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.consts.WeChatConsts;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.common.utils.IPUtil;
import com.ibiaoke.customer.entity.Customer;
import com.ibiaoke.customer.entity.vo.DepositVO;
import com.ibiaoke.customer.service.DepositService;
import com.ibiaoke.marketing.dao.CouponDao;
import com.ibiaoke.marketing.entity.Coupon;
import com.ibiaoke.order.service.xcxDepositService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

@Controller
public class XcxDepositController extends BaseController{

    @Autowired
    private DepositService depositService;
    @Autowired
    private CouponDao couponDao;
    @Autowired
    private xcxDepositService xcxDepositService;

    /**
     * 获取账户余额
     * @return
     */
    @RequestMapping("/xcxGetDeposit")
    @ResponseBody
    public Res xcxGetDeposit() {
        Customer customer = getLoginUser();
        DepositVO deposit = depositService.getDeposit(customer.getCustomerId());
        Coupon coupon = couponDao.getCouponById(customer.getCustomerId());
        return new Res().addResponse("deposit", deposit).addResponse("totalCount",coupon.getTotalCount());
    }

    /**
     * 余额充值(微信，支付宝)
     * @param money
     * @param payType
     * @return
     */
    @RequestMapping("/xcxDepositCharge")
    @ResponseBody
    public Res xcxDepositCharge(BigDecimal money, Integer payType, HttpServletRequest request) {
        Customer customer = getLoginUser();
        String openId= (String) getSession().getAttribute(WeChatConsts.Xcx_Id);
        String ip = IPUtil.getIp(request);
        return xcxDepositService.xcxDepositCharge(customer.getCustomerId(),money, payType,openId,ip);
    }
}
